﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace ToolCalendar.Helper
{
    public class FileHelper
    {
        #region 文件流操作

        /// <summary>
        /// 读取文件为 byte[]
        /// </summary>
        /// <param name="path">文件路径:绝对路径</param>
        /// <param name="str">写入内容</param>
        /// <param name="append">是否追加</param>
        /// <param name="encoding">编码格式</param>
        public static byte[] FileToBytes(string path)
        {
            FileStream Fs = new FileStream(path, FileMode.Open);
            int fsLen = (int)Fs.Length;
            byte[] bytes = new byte[fsLen];
            Fs.Read(bytes, 0, bytes.Length);
            Fs.Close();

            return bytes;
        }

        /// <summary>
        /// byte[] 保存为 文件
        /// </summary>
        /// <param name="path">文件路径:绝对路径</param>
        /// <param name="encoding">编码格式</param>
        public static void BytesToFile(byte[] bytes, string saveFile)
        {
            FileStream fsWrite = new FileStream(saveFile, FileMode.Create);
            fsWrite.Write(bytes, 0, bytes.Length);
            fsWrite.Close();
        }
        #endregion 文件读写
    }
}
